<template>
  <div class="detail">
    <div class="detail-info">
      <div class="detail-info-status">
        <span>{{ rec.info.equipmentRepair?.repairTypeName }}</span>
        <span v-if="rec.info.equipmentRepair?.status === 1">已维修</span>
        <span class="orange" v-else>待维修</span>
      </div>

      <div class="detail-info-address">
        <svg-icon icon-class="mark" />
        <span class="ellipsisStyle"
          >{{ rec.info.equipmentRepair?.buildingLocationName }}/{{
            rec.info.equipmentRepair?.roomLocationName
          }}</span
        >
      </div>

      <div class="detail-info-time">
        <svg-icon icon-class="time" />
        <span>{{
          dayjs(rec.info.equipmentRepair?.createTime).format("YYYY-MM-DD hh:mm")
        }}</span>
      </div>

      <div class="detail-info-content">
        {{ rec.info.equipmentRepair?.repairDesc }}
      </div>

      <PreviewComp :imgList="rec.imgList" :videoList="rec.videoList" />
    </div>
    <!-- 报修人查看维修详情 -->
    <div v-if="rec.type === 'home'">
      <FixDetail :list="rec.info.equipmentRepairResult" />
    </div>

    <!-- 查看报修人填报信息 -->
    <div v-else>
      <RepairDetail
        :list="rec.info.equipmentRepairResult"
        :info="rec.info.equipmentRepair"
      />
    </div>
  </div>
</template>

<script lang="ts" setup>
import { reactive } from "vue";
import { getRepairDetail } from "@/service/modules/repair";
import { useRoute } from "vue-router";
import FixDetail from "./cpns/FixDetail.vue";
import RepairDetail from "./cpns/RepairDetail.vue";
import PreviewComp from "@/components/previewComp/index.vue";
import { isImage } from "@/utils/utils";
import * as dayjs from "dayjs";
document.title = "报修详情";
const route = useRoute();
const rec = reactive({
  info: {},
  repairDesc: "",
  type: route.query.type,
  imgList: [],
  videoList: [],
});

// 获取详情
getDetailFn();
async function getDetailFn() {
  const id = route.query.id;
  const { code, data } = await getRepairDetail(id);
  if (code === 0) {
    rec.info = data;
    rec.imgList = data.equipmentRepairFiles
      .filter((i) => isImage(i.url))
      .map((k) => k.url);
    rec.videoList = data.equipmentRepairFiles
      .filter((i) => !isImage(i.url))
      .map((k) => k.url);
  }
}
</script>

<style lang="less" scoped>
.detail {
  background: #fff;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  &-info {
    padding: 8px 16px;
    background: #fff;
    &-status {
      display: flex;
      justify-content: space-between;
      align-items: center;
      > span:first-child {
        font-size: 18px;
        line-height: 40px;
        font-weight: bold;
        color: #303233;
      }
      > span:nth-child(2),
      .orange {
        width: 56px;
        height: 24px;
        background: #dcdcdc;
        border-radius: 4px;
        font-size: 12px;
        line-height: 24px;
        color: #fff;
        text-align: center;
      }
      .orange {
        background: #fe922a !important;
      }
    }
    &-address,
    &-time {
      display: flex;
      align-items: center;
      margin-top: 8px;
      svg {
        margin-right: 11px;
      }
      > span {
        font-size: 14px;
        line-height: 22px;
        color: #303233;
      }
    }
    &-address {
      svg {
        margin-right: 13px;
      }
    }
    &-content {
      margin-top: 12px;
      font-size: 14px;
      line-height: 32px;
      color: #303233;
    }
    &-imgs {
      margin-top: 8px;
      display: flex;
      // justify-content: space-evenly;
      > div {
        width: 108px;
        height: 108px;
        border-radius: 4px;
        margin-right: 4px;
        margin-bottom: 8px;
        img {
          width: 100%;
          height: 100%;
        }
      }
    }
  }
}
</style>
